package com.youyi.yyviewsdklibrary.Dialog.core;

import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.youyi.yyviewsdklibrary.Dialog.XPopup;
import com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.ScaleAlphaAnimator;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupAnimation;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupPosition;
import com.youyi.yyviewsdklibrary.Dialog.util.XPopupUtils;
import com.youyi.yyviewsdklibrary.Dialog.widget.BubbleLayout;
import com.lkx.liandianqinew.R;

public abstract class BubbleAttachPopupView extends BasePopupView {
    protected BubbleLayout bubbleContainer = ((BubbleLayout) findViewById(R.id.bubbleContainer));
    float centerY = 0.0f;
    protected int defaultOffsetX = 0;
    protected int defaultOffsetY = 0;
    public boolean isShowLeft;
    public boolean isShowUp;
    float maxY = ((float) XPopupUtils.getAppHeight(getContext()));
    int overflow = XPopupUtils.dp2px(getContext(), 10.0f);
    float translationX = 0.0f;
    float translationY = 0.0f;

    public BubbleAttachPopupView(Context context) {
        super(context);
    }

    /* access modifiers changed from: protected */
    public void addInnerContent() {
        this.bubbleContainer.addView(LayoutInflater.from(getContext()).inflate(getImplLayoutId(), (ViewGroup) this.bubbleContainer, false));
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public final int getInnerLayoutId() {
        return R.layout._xpopup_bubble_attach_popup_view;
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void initPopupContent() {
        super.initPopupContent();
        if (this.bubbleContainer.getChildCount() == 0) {
            addInnerContent();
        }
        if (this.popupInfo.atView == null && this.popupInfo.touchPoint == null) {
            throw new IllegalArgumentException("atView() or watchView() must be called for BubbleAttachPopupView before show()！");
        }
        if (Build.VERSION.SDK_INT >= 21) {
            this.bubbleContainer.setElevation((float) XPopupUtils.dp2px(getContext(), 10.0f));
        }
        this.bubbleContainer.setShadowRadius(XPopupUtils.dp2px(getContext(), 0.0f));
        this.defaultOffsetY = this.popupInfo.offsetY;
        this.defaultOffsetX = this.popupInfo.offsetX;
        XPopupUtils.applyPopupSize((ViewGroup) getPopupContentView(), getMaxWidth(), getMaxHeight(), getPopupWidth(), getPopupHeight(), new Runnable() {
            /* class com.youyi.yyviewsdklibrary.Dialog.core.BubbleAttachPopupView.AnonymousClass1 */

            public void run() {
                BubbleAttachPopupView.this.doAttach();
            }
        });
    }

    public void doAttach() {
        int i;
        int i2;
        int i3;
        float f;
        this.maxY = (float) (XPopupUtils.getAppHeight(getContext()) - this.overflow);
        final boolean isLayoutRtl = XPopupUtils.isLayoutRtl(getContext());
        boolean z = true;
        if (this.popupInfo.touchPoint != null) {
            if (XPopup.longClickPoint != null) {
                this.popupInfo.touchPoint = XPopup.longClickPoint;
            }
            this.centerY = this.popupInfo.touchPoint.y;
            if (this.popupInfo.touchPoint.y + ((float) getPopupContentView().getMeasuredHeight()) > this.maxY) {
                this.isShowUp = this.popupInfo.touchPoint.y > ((float) (XPopupUtils.getScreenHeight(getContext()) / 2));
            } else {
                this.isShowUp = false;
            }
            if (this.popupInfo.touchPoint.x >= ((float) (XPopupUtils.getAppWidth(getContext()) / 2))) {
                z = false;
            }
            this.isShowLeft = z;
            ViewGroup.LayoutParams layoutParams = getPopupContentView().getLayoutParams();
            if (isShowUpToTarget()) {
                f = this.popupInfo.touchPoint.y - ((float) XPopupUtils.getStatusBarHeight());
                i3 = this.overflow;
            } else {
                f = ((float) XPopupUtils.getScreenHeight(getContext())) - this.popupInfo.touchPoint.y;
                i3 = this.overflow;
            }
            int i4 = (int) (f - ((float) i3));
            int appWidth = (int) ((this.isShowLeft ? ((float) XPopupUtils.getAppWidth(getContext())) - this.popupInfo.touchPoint.x : this.popupInfo.touchPoint.x) - ((float) this.overflow));
            if (getPopupContentView().getMeasuredHeight() > i4) {
                layoutParams.height = i4;
            }
            if (getPopupContentView().getMeasuredWidth() > appWidth) {
                layoutParams.width = appWidth;
            }
            getPopupContentView().setLayoutParams(layoutParams);
            getPopupContentView().post(new Runnable() {
                /* class com.youyi.yyviewsdklibrary.Dialog.core.BubbleAttachPopupView.AnonymousClass2 */

                public void run() {
                    float f;
                    if (isLayoutRtl) {
                        BubbleAttachPopupView bubbleAttachPopupView = BubbleAttachPopupView.this;
                        if (bubbleAttachPopupView.isShowLeft) {
                            f = ((((float) XPopupUtils.getAppWidth(BubbleAttachPopupView.this.getContext())) - BubbleAttachPopupView.this.popupInfo.touchPoint.x) - ((float) BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth())) - ((float) BubbleAttachPopupView.this.defaultOffsetX);
                        } else {
                            f = (((float) XPopupUtils.getAppWidth(BubbleAttachPopupView.this.getContext())) - BubbleAttachPopupView.this.popupInfo.touchPoint.x) + ((float) BubbleAttachPopupView.this.defaultOffsetX);
                        }
                        bubbleAttachPopupView.translationX = -f;
                    } else {
                        BubbleAttachPopupView bubbleAttachPopupView2 = BubbleAttachPopupView.this;
                        bubbleAttachPopupView2.translationX = bubbleAttachPopupView2.isShowLeft ? BubbleAttachPopupView.this.popupInfo.touchPoint.x + ((float) BubbleAttachPopupView.this.defaultOffsetX) : (BubbleAttachPopupView.this.popupInfo.touchPoint.x - ((float) BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth())) - ((float) BubbleAttachPopupView.this.defaultOffsetX);
                    }
                    if (BubbleAttachPopupView.this.popupInfo.isCenterHorizontal) {
                        if (BubbleAttachPopupView.this.isShowLeft) {
                            if (isLayoutRtl) {
                                BubbleAttachPopupView.this.translationX += ((float) BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth()) / 2.0f;
                            } else {
                                BubbleAttachPopupView.this.translationX -= ((float) BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth()) / 2.0f;
                            }
                        } else if (isLayoutRtl) {
                            BubbleAttachPopupView.this.translationX -= ((float) BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth()) / 2.0f;
                        } else {
                            BubbleAttachPopupView.this.translationX += ((float) BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth()) / 2.0f;
                        }
                    }
                    if (BubbleAttachPopupView.this.isShowUpToTarget()) {
                        BubbleAttachPopupView bubbleAttachPopupView3 = BubbleAttachPopupView.this;
                        bubbleAttachPopupView3.translationY = (bubbleAttachPopupView3.popupInfo.touchPoint.y - ((float) BubbleAttachPopupView.this.getPopupContentView().getMeasuredHeight())) - ((float) BubbleAttachPopupView.this.defaultOffsetY);
                    } else {
                        BubbleAttachPopupView bubbleAttachPopupView4 = BubbleAttachPopupView.this;
                        bubbleAttachPopupView4.translationY = bubbleAttachPopupView4.popupInfo.touchPoint.y + ((float) BubbleAttachPopupView.this.defaultOffsetY);
                    }
                    if (BubbleAttachPopupView.this.isShowUpToTarget()) {
                        BubbleAttachPopupView.this.bubbleContainer.setLook(BubbleLayout.Look.BOTTOM);
                    } else {
                        BubbleAttachPopupView.this.bubbleContainer.setLook(BubbleLayout.Look.TOP);
                    }
                    if (BubbleAttachPopupView.this.popupInfo.isCenterHorizontal) {
                        BubbleAttachPopupView.this.bubbleContainer.setLookPositionCenter(true);
                    } else if (BubbleAttachPopupView.this.isShowLeft) {
                        BubbleAttachPopupView.this.bubbleContainer.setLookPosition(XPopupUtils.dp2px(BubbleAttachPopupView.this.getContext(), 1.0f));
                    } else {
                        BubbleAttachPopupView.this.bubbleContainer.setLookPosition(BubbleAttachPopupView.this.bubbleContainer.getMeasuredWidth() - XPopupUtils.dp2px(BubbleAttachPopupView.this.getContext(), 1.0f));
                    }
                    BubbleAttachPopupView.this.bubbleContainer.invalidate();
                    BubbleAttachPopupView.this.translationX -= (float) BubbleAttachPopupView.this.getActivityContentLeft();
                    BubbleAttachPopupView.this.getPopupContentView().setTranslationX(BubbleAttachPopupView.this.translationX);
                    BubbleAttachPopupView.this.getPopupContentView().setTranslationY(BubbleAttachPopupView.this.translationY);
                    BubbleAttachPopupView.this.initAndStartAnimation();
                }
            });
            return;
        }
        final Rect atViewRect = this.popupInfo.getAtViewRect();
        int i5 = (atViewRect.left + atViewRect.right) / 2;
        boolean z2 = ((float) (atViewRect.bottom + getPopupContentView().getMeasuredHeight())) > this.maxY;
        this.centerY = (float) ((atViewRect.top + atViewRect.bottom) / 2);
        if (z2) {
            this.isShowUp = true;
        } else {
            this.isShowUp = false;
        }
        if (i5 >= XPopupUtils.getAppWidth(getContext()) / 2) {
            z = false;
        }
        this.isShowLeft = z;
        ViewGroup.LayoutParams layoutParams2 = getPopupContentView().getLayoutParams();
        if (isShowUpToTarget()) {
            i2 = atViewRect.top - XPopupUtils.getStatusBarHeight();
            i = this.overflow;
        } else {
            i2 = XPopupUtils.getScreenHeight(getContext()) - atViewRect.bottom;
            i = this.overflow;
        }
        int i6 = i2 - i;
        int appWidth2 = (this.isShowLeft ? XPopupUtils.getAppWidth(getContext()) - atViewRect.left : atViewRect.right) - this.overflow;
        if (getPopupContentView().getMeasuredHeight() > i6) {
            layoutParams2.height = i6;
        }
        if (getPopupContentView().getMeasuredWidth() > appWidth2) {
            layoutParams2.width = appWidth2;
        }
        getPopupContentView().setLayoutParams(layoutParams2);
        getPopupContentView().post(new Runnable() {
            /* class com.youyi.yyviewsdklibrary.Dialog.core.BubbleAttachPopupView.AnonymousClass3 */

            public void run() {
                int i;
                if (isLayoutRtl) {
                    BubbleAttachPopupView bubbleAttachPopupView = BubbleAttachPopupView.this;
                    if (bubbleAttachPopupView.isShowLeft) {
                        i = ((XPopupUtils.getAppWidth(BubbleAttachPopupView.this.getContext()) - atViewRect.left) - BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth()) - BubbleAttachPopupView.this.defaultOffsetX;
                    } else {
                        i = (XPopupUtils.getAppWidth(BubbleAttachPopupView.this.getContext()) - atViewRect.right) + BubbleAttachPopupView.this.defaultOffsetX;
                    }
                    bubbleAttachPopupView.translationX = (float) (-i);
                } else {
                    BubbleAttachPopupView bubbleAttachPopupView2 = BubbleAttachPopupView.this;
                    bubbleAttachPopupView2.translationX = (float) ((bubbleAttachPopupView2.isShowLeft ? atViewRect.left : atViewRect.right - BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth()) + BubbleAttachPopupView.this.defaultOffsetX);
                }
                if (BubbleAttachPopupView.this.popupInfo.isCenterHorizontal) {
                    if (BubbleAttachPopupView.this.isShowLeft) {
                        if (isLayoutRtl) {
                            BubbleAttachPopupView.this.translationX -= ((float) (atViewRect.width() - BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth())) / 2.0f;
                        } else {
                            BubbleAttachPopupView.this.translationX += ((float) (atViewRect.width() - BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth())) / 2.0f;
                        }
                    } else if (isLayoutRtl) {
                        BubbleAttachPopupView.this.translationX += ((float) (atViewRect.width() - BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth())) / 2.0f;
                    } else {
                        BubbleAttachPopupView.this.translationX -= ((float) (atViewRect.width() - BubbleAttachPopupView.this.getPopupContentView().getMeasuredWidth())) / 2.0f;
                    }
                }
                if (BubbleAttachPopupView.this.isShowUpToTarget()) {
                    BubbleAttachPopupView.this.translationY = (float) ((atViewRect.top - BubbleAttachPopupView.this.getPopupContentView().getMeasuredHeight()) - BubbleAttachPopupView.this.defaultOffsetY);
                } else {
                    BubbleAttachPopupView.this.translationY = (float) (atViewRect.bottom + BubbleAttachPopupView.this.defaultOffsetY);
                }
                if (BubbleAttachPopupView.this.isShowUpToTarget()) {
                    BubbleAttachPopupView.this.bubbleContainer.setLook(BubbleLayout.Look.BOTTOM);
                } else {
                    BubbleAttachPopupView.this.bubbleContainer.setLook(BubbleLayout.Look.TOP);
                }
                if (BubbleAttachPopupView.this.popupInfo.isCenterHorizontal) {
                    BubbleAttachPopupView.this.bubbleContainer.setLookPositionCenter(true);
                } else {
                    BubbleAttachPopupView.this.bubbleContainer.setLookPosition((int) (((float) ((atViewRect.left + (atViewRect.width() / 2)) - (BubbleAttachPopupView.this.bubbleContainer.mLookWidth / 2))) - BubbleAttachPopupView.this.translationX));
                }
                BubbleAttachPopupView.this.bubbleContainer.invalidate();
                BubbleAttachPopupView.this.translationX -= (float) BubbleAttachPopupView.this.getActivityContentLeft();
                BubbleAttachPopupView.this.getPopupContentView().setTranslationX(BubbleAttachPopupView.this.translationX);
                BubbleAttachPopupView.this.getPopupContentView().setTranslationY(BubbleAttachPopupView.this.translationY);
                BubbleAttachPopupView.this.initAndStartAnimation();
            }
        });
    }

    /* access modifiers changed from: protected */
    public void initAndStartAnimation() {
        initAnimator();
        doShowAnimation();
        doAfterShow();
    }

    /* access modifiers changed from: protected */
    public boolean isShowUpToTarget() {
        if (this.popupInfo.positionByWindowCenter) {
            if (this.centerY > ((float) (XPopupUtils.getAppHeight(getContext()) / 2))) {
                return true;
            }
            return false;
        } else if ((this.isShowUp || this.popupInfo.popupPosition == PopupPosition.Top) && this.popupInfo.popupPosition != PopupPosition.Bottom) {
            return true;
        } else {
            return false;
        }
    }

    public BubbleAttachPopupView setBubbleBgColor(int i) {
        this.bubbleContainer.setBubbleColor(i);
        this.bubbleContainer.invalidate();
        return this;
    }

    public BubbleAttachPopupView setBubbleRadius(int i) {
        this.bubbleContainer.setBubbleRadius(i);
        this.bubbleContainer.invalidate();
        return this;
    }

    public BubbleAttachPopupView setArrowWidth(int i) {
        this.bubbleContainer.setLookWidth(i);
        this.bubbleContainer.invalidate();
        return this;
    }

    public BubbleAttachPopupView setArrowHeight(int i) {
        this.bubbleContainer.setLookLength(i);
        this.bubbleContainer.invalidate();
        return this;
    }

    public BubbleAttachPopupView setBubbleShadowSize(int i) {
        this.bubbleContainer.setShadowRadius(i);
        this.bubbleContainer.invalidate();
        return this;
    }

    public BubbleAttachPopupView setBubbleShadowColor(int i) {
        this.bubbleContainer.setShadowColor(i);
        this.bubbleContainer.invalidate();
        return this;
    }

    public BubbleAttachPopupView setArrowRadius(int i) {
        this.bubbleContainer.setArrowRadius(i);
        this.bubbleContainer.invalidate();
        return this;
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public PopupAnimator getPopupAnimator() {
        return new ScaleAlphaAnimator(getPopupContentView(), getAnimationDuration(), PopupAnimation.ScaleAlphaFromCenter);
    }
}
